#include "intrp2d_u16u32u16n16la_se.h"
#include "rtwtypes.h"

uint16_T intrp2d_u16u32u16n16la_se(const uint32_T bpIndex[], const uint16_T
  frac[], const uint16_T table[], const uint32_T stride, const uint32_T
  maxIndex[])
{
  uint32_T offset_1d;
  uint16_T y;
  uint16_T yL_0d0;
  uint16_T yR_0d0;
  offset_1d = bpIndex[1U] * stride + bpIndex[0U];
  if (bpIndex[0U] == maxIndex[0U]) {
    y = table[offset_1d];
  } else {
    yR_0d0 = table[offset_1d + 1U];
    yL_0d0 = table[offset_1d];
    if (yR_0d0 >= yL_0d0) {
      y = (uint16_T)((uint32_T)(uint16_T)(((uint32_T)(uint16_T)((uint32_T)yR_0d0
        - yL_0d0) * frac[0U]) >> 16) + yL_0d0);
    } else {
      y = (uint16_T)((uint32_T)yL_0d0 - (uint16_T)(((uint32_T)(uint16_T)
        ((uint32_T)yL_0d0 - yR_0d0) * frac[0U]) >> 16));
    }
  }

  if (bpIndex[1U] == maxIndex[1U]) {
  } else {
    offset_1d += stride;
    if (bpIndex[0U] == maxIndex[0U]) {
      yR_0d0 = table[offset_1d];
    } else {
      yR_0d0 = table[offset_1d + 1U];
      yL_0d0 = table[offset_1d];
      if (yR_0d0 >= yL_0d0) {
        yR_0d0 = (uint16_T)((uint32_T)(uint16_T)(((uint32_T)(uint16_T)((uint32_T)
          yR_0d0 - yL_0d0) * frac[0U]) >> 16) + yL_0d0);
      } else {
        yR_0d0 = (uint16_T)((uint32_T)yL_0d0 - (uint16_T)(((uint32_T)(uint16_T)
          ((uint32_T)yL_0d0 - yR_0d0) * frac[0U]) >> 16));
      }
    }

    if (yR_0d0 >= y) {
      y = (uint16_T)((uint32_T)(uint16_T)(((uint32_T)(uint16_T)((uint32_T)yR_0d0
        - y) * frac[1U]) >> 16) + y);
    } else {
      y = (uint16_T)((uint32_T)y - (uint16_T)(((uint32_T)(uint16_T)((uint32_T)y
        - yR_0d0) * frac[1U]) >> 16));
    }
  }

  return y;
}
